package kr.hkit.androidcomplete03.ch20;

import kr.hkit.androidcomplete03.R;
import android.app.Activity;
import android.app.ListFragment;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class WordListFragment extends ListFragment {
	OnWordChangedListener mListener;
	
	public interface OnWordChangedListener{
		public void onWordChanged(int index);
		
	}
	public void onAttach(Activity activity){
		super.onAttach(activity);
		try{
			mListener =(OnWordChangedListener) activity;
		}catch(ClassCastException e){
			throw new ClassCastException("해당 액티비티는 인터페이스 OnWordChangedListener를 구현해야 함");
		}
	}
	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
		String[] WORD=getResources().getStringArray(R.array.word);
		setListAdapter(new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1,WORD));
		getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);
		
		
	}
	@Override
	public void onListItemClick(ListView l, View v, int position, long id) {
		super.onListItemClick(l, v, position, id);
		mListener.onWordChanged(position);
	}
}
